package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4FlatMap {
  def main(args: Array[String]): Unit = {
    //创建Spark环境
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("map")

    val sc = new SparkContext(conf)

    //将一个scala集合转换成RDD,一班用于测试
    val listRDD: RDD[String] = sc.parallelize(List("java,spark,hadoop", "scala,java,hadoop"))

    /**
     * flatMap: 以原RDD中的一行转换成多行
     */
    val wordsRDD: RDD[String] = listRDD
      .flatMap(line => line.split(","))

    wordsRDD.foreach(println)
  }

}
